#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <math.h>

#define NOISY_TEST 1

//most of the structure and random functions were borrowed from betterTestDrawCard


int checkfullDeckcount(int p, int card, struct gameState *post, int cardCount) {
  int r;
  int errornum = 0;
  r = fullDeckCount(p, card, post); //call the real function and pass the player, card, and state
  //assert(r == cardCount); //does the real function and the cardCount match?

  if (r != cardCount) {
  	  errornum++;
    }



  return 0;

}

int main() {
	int i;
	int j;
	int p;
	int n;
	int cardCount;
	int cardNumber;

	struct gameState G;

	printf ("Testing fullDeckCount():\n");

	//exact copy from betterTestDrawCard.c
	SelectStream(2);
	PutSeed(3);

	for (n = 0; n < 2000; n++) {
	    for (i = 0; i < sizeof(struct gameState); i++) {
	      ((char*)&G)[i] = floor(Random() * 256);
	    }

	// end of exact copy


	 p = floor(Random() * MAX_PLAYERS); //make number of players random
	 cardNumber = floor(Random() * 25); //make the card number random
	 cardCount = 0;

	 //set the deck count for a player to a random number
	 G.deckCount[p] = floor(Random() * MAX_DECK);
	 	 //go through the player deck
	 	 for (j=0; j < G.deckCount[p]; j++){
	 		 G.deck[p][j] = floor(Random() * 25); //set the player 1 card 1 to a random number
	 		 if (G.deck[p][j] == cardNumber) //if the player 1 card 1 is a valid card number
	 			 	cardCount++; //increase the count
	 	 }

	 //set the discard deck count for a player to a random number
	 G.discardCount[p] = floor(Random() * MAX_DECK);
	 //go through the player discard deck
	 	 	 for (j=0; j < G.discardCount[p]; j++){
	 	 		 G.discard[p][j] = floor(Random() * 25); //set the player 1 discard card 1 to a random number
	 	 		 if (G.discard[p][j] == cardNumber) //if the player 1 discard card 1 is a valid card number
	 	 			 	cardCount++; //increase the count
	 	 	 }

	 //set the hand count for a player to a random number
	 G.handCount[p] = floor(Random() * MAX_HAND);
	 //go through the player hand
	 	 	 	 for (j=0; j < G.handCount[p]; j++){
	 	 	 		 G.hand[p][j] = floor(Random() * 25); //set the player 1 hand card 1 to a random number
	 	 	 		 if (G.hand[p][j] == cardNumber) //if the player 1 hand card 1 is a valid card number
	 	 	 			 	cardCount++; //increase the count
	 	 	 	 }


	 	 		 checkfullDeckcount(p, cardNumber, &G, cardCount);
	}


	 printf ("ALL TESTS OK\n");

	return 0;
}
